<?php
/**
* エラーチェッククラス
**/
require_once( '../system/Class_M_DAO.php' );
class Class_M_COST_FLIER_PRICE extends Class_M_DAO {
	//protected properties begin
	/**
	 *
	 * テーブル名
	 *
	 * @access    protected
	 * @var       string
	 *
	 */
	protected $_table  = "M_COST_FLIER_PRICE";
	
	/**
	 *
	 * 主キー名
	 *
	 * @access    protected
	 * @var       string
	 *
	 */
	protected $_pkey   = "id";
	
	/**
	 *
	 * ソート順
	 *
	 * @access    protected
	 * @var       string
	 *
	 */
	 protected $_order = "id";
	 
	 protected $_cols  =  array(
		"shop_cd"   => array(AOKI_VARTYPE_STR),
		"year4"     => array(AOKI_VARTYPE_INT),
		"size"      => array(AOKI_VARTYPE_STR),
		"price"     => array(AOKI_VARTYPE_INT)

	 );
	
	 protected $_checks  =  array(
		"shop_cd"      => array( "EXIST","NUM" ),
		"price"        => array( "NUM" )
	 );
	 
	 //maxlength 
	 protected $_maxlens  = array(
		"shop_cd "        => 3 
	 );
	
	 public function search($where ,&$page = NULL, $matrix_cd ){	
		return  parent::search($where, $page);
	}
	
	public function getsearch( $where, $year4 = 0){

	 	$fromtable = "  from M_SHOP  c
 left join  (select shop_cd,
 sum(case size when 'B2' then price else 0 end) as 'b2',
 sum(case size when 'B3' then price else 0 end) as 'b3',
 sum(case size when 'B4' then price else 0 end) as 'b4' 
 from M_COST_FLIER_PRICE where year4='{$year4}' 
 group by shop_cd ) p on p.shop_cd = c.shop_cd ";
	 	$select    = " SELECT  c.shop_cd,c.shop_name,p.b2,p.b3,p.b4 ";
	 	$order     = " ORDER BY c.shop_cd ";
		
		$where = implode(' AND ', $where);
		if ($where) {
			$where = " WHERE ".$where;
		}
		
		$sql =  $select.$fromtable.$where.$order ;
	
		try {
			$this->_db->query( $sql );
			$data = array();
			while( $row = $this->_db->fetch() ){
				$data[] = $row;
			}
			return $data;
			
		} catch (Exception $e) {
			echo "例外キャッチ：", $e->getMessage(), "\n";
			return NULL;
		}
	}
}

?>